package com.example.shellcollector.Entity;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;

/**
 * Represents the usage of an app in a specific day.
 */
@Entity(
        tableName = "app_daily_usage",
        foreignKeys = {
                @ForeignKey(
                        entity = InstalledAppUsage.class,
                        parentColumns = { "id" },
                        childColumns = { "app_id" },
                        onDelete = ForeignKey.CASCADE,
                        onUpdate = ForeignKey.CASCADE
                )
        },
        indices = {
                @Index(value = { "app_id", "date" }, unique = true)
        }
)
public class AppDailyUsage {

    @PrimaryKey(autoGenerate = true)
    private int id;

    /**
     * reference an installed app
     */
    @ColumnInfo(name = "app_id", index = true)
    private int appId;

    /**
     * the timestamp at 00:00 of the day
     */
    private long date;

    /**
     * app total running time today in milliseconds
     */
    @ColumnInfo(name = "total_running_time")
    private long totalRunningTime;

    /**
     * app first running timestamp today
     */
    @ColumnInfo(name = "first_running_time")
    private long firstRunningTime;

    /**
     * app last running timestamp today
     */
    @ColumnInfo(name = "last_running_time")
    private long lastRunningTime;

    /**
     * app launch count of the day
     */
    @ColumnInfo(name = "launch_count")
    private int launchCount;

    public AppDailyUsage() {}

    @Ignore
    public AppDailyUsage(long date, long totalRunningTime) {
        this.date = date;
        this.totalRunningTime = totalRunningTime;
    }

    public long getDate() {
        return date;
    }

    public long getTotalRunningTime() {
        return totalRunningTime;
    }

    public void setDate(long date) {
        this.date = date;
    }

    public void setTotalRunningTime(long totalRunningTime) {
        this.totalRunningTime = totalRunningTime;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAppId() {
        return appId;
    }

    public void setAppId(int appId) {
        this.appId = appId;
    }

    public int getLaunchCount() {
        return launchCount;
    }

    public void setLaunchCount(int launchCount) {
        this.launchCount = launchCount;
    }

    public long getFirstRunningTime() {
        return firstRunningTime;
    }

    public void setFirstRunningTime(long firstRunningTime) {
        this.firstRunningTime = firstRunningTime;
    }

    public long getLastRunningTime() {
        return lastRunningTime;
    }

    public void setLastRunningTime(long lastRunningTime) {
        this.lastRunningTime = lastRunningTime;
    }
}
